package com.hangzhou.welbeing.welbeinginstrument.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hangzhou.welbeing.welbeinginstrument.R;
import com.hangzhou.welbeing.welbeinginstrument.bean.RecommendedPeopleDateBean;
import com.hangzhou.welbeing.welbeinginstrument.config.RBConstants;
import com.hangzhou.welbeing.welbeinginstrument.inteface.OnRecyclerViewItemClickListener;
import com.hangzhou.welbeing.welbeinginstrument.tool.GlideCircleTransform;

import java.util.ArrayList;
import java.util.List;

/**
 * 时间 2017 年 09 月 07.
 * 作者 Administrator  刘传华
 * 公司 杭州惟君医疗科技有限公司
 * 包名 com.hangzhou.welbeing.pregnant.welbeing_pregnant.adapter
 * 工程名 welbeing_pregnant
 */
public class RecommendedCirclesAdapter  extends  RecyclerView.Adapter<RecommendedCirclesAdapter.ViewHolder> implements View.OnClickListener {
    private static final String TAG = "RecommendedCirclesAdapter";
    private OnRecyclerViewItemClickListener mOnItemClickListener = null;
    private List<RecommendedPeopleDateBean.DataBean> mlist = new ArrayList<>();
    private Context mcontext;
    public RecommendedCirclesAdapter(List<RecommendedPeopleDateBean.DataBean> mlist1, Context context) {
        mlist.addAll(mlist1);
        mcontext = context;
    }

    public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recommended_circles_recyclerview,parent,false);
        ViewHolder viewHolder = new ViewHolder(view);
        view.setOnClickListener(this);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        String logo = mlist.get(position).cus_logo;
        if(logo == null){

        }else{
            Glide.with(mcontext).load(RBConstants.SERVER_URL+"/Public/Uploads/"+mlist.get(position).cus_logo).transform(new GlideCircleTransform(mcontext)).into(holder.iv_circle_picture);
        }
        holder.tv_titiles.setText(mlist.get(position).cus_name);
       String signature =  mlist.get(position).signature;
        if(signature == null ||signature.equals("")){

        }else{
            holder.tv_content.setText(mlist.get(position).signature);
        }
        int att = mlist.get(position).att;
        if(att == 0){
            holder.tv_attention.setText("关注");
        }else if(att == 1){
            holder.tv_attention.setText("已关注");
        }

    }

    @Override
    public int getItemCount() {
        return mlist.size();
    }

    @Override
    public void onClick(View view) {
        if(mOnItemClickListener != null ){
            mOnItemClickListener.onItemClick(view);
        }
    }

    /**
     * 身体布局Holder
     */
    static class ViewHolder extends RecyclerView.ViewHolder {
        private TextView tv_titiles;
        private  TextView tv_content;
        private  TextView tv_attention;
        private ImageView iv_circle_picture;
        public ViewHolder(View itemView) {
            super(itemView);
            tv_titiles =  (TextView) itemView.findViewById(R.id.item_recommended_circles_recyclerview_tv_titiles);
            tv_content =  (TextView) itemView.findViewById(R.id.item_recommended_circles_recyclerview_tv_content);
            tv_attention =  (TextView) itemView.findViewById(R.id.item_recommended_circles_recyclerview_tv_attention);
            iv_circle_picture =  (ImageView) itemView.findViewById(R.id.item_recommended_circles_recyclerview_iv_circle_picture);
        }
    }
}
